package cn.icare.cms;

public class Test {
    public static void main(String[] args) {
        String sourceString = "234";

        char[] tempCharArray = sourceString.toCharArray();
        String[][] doubleArray = new String[tempCharArray.length][];
        for (int i = 0; i < doubleArray.length; i++) {
            String[] stringArray = getStringArray(Character.toString(tempCharArray[i]));
            if (stringArray != null) {
                doubleArray[i] = stringArray;
            }
        }

        String[][] tempResult = recursiveHandle(doubleArray);
        String[] result = tempResult[0];
        System.out.println(String.format("共有%s种排列组合", result.length));
        for (int i = 0; i < result.length; i++) {
            System.out.println(result[i]);
        }
    }

    private static String[][] recursiveHandle(String[][] doubleArray) {
        int tempLength = doubleArray.length;
        if (tempLength >= 2) {
            int tempLengthOne = doubleArray[0].length;
            int tempLengthTwo = doubleArray[1].length;
            int newLength = tempLengthOne * tempLengthTwo;
            String[] tempArray = new String[newLength];
            int index = 0;
            for (int i = 0; i < tempLengthOne; i++) {
                for (int j = 0; j < tempLengthTwo; j++) {
                    tempArray[index] = doubleArray[0][i] + doubleArray[1][j];
                    index++;
                }
            }
            String[][] newArray = new String[tempLength - 1][];
            for (int i = 2; i < tempLength; i++) {
                newArray[i - 1] = doubleArray[i];
            }
            newArray[0] = tempArray;
            return recursiveHandle(newArray);
        } else {
            return doubleArray;
        }
    }

    private static String[] getStringArray(String number) {
        String[] result = new String[3];
        switch (number) {
            case "2":
                result[0] = "A";
                result[1] = "B";
                result[2] = "C";
                break;
            case "3":
                result[0] = "D";
                result[1] = "E";
                result[2] = "F";
                break;
            case "4":
                result[0] = "G";
                result[1] = "H";
                result[2] = "I";
                break;
            case "5":
                result[0] = "J";
                result[1] = "K";
                result[2] = "L";
                break;
            case "6":
                result[0] = "M";
                result[1] = "N";
                result[2] = "O";
                break;
            case "7":
                result = new String[4];
                result[0] = "P";
                result[1] = "Q";
                result[2] = "R";
                result[3] = "S";
                break;
            case "8":
                result[0] = "T";
                result[1] = "U";
                result[2] = "V";
                break;
            case "9":
                result = new String[4];
                result[0] = "W";
                result[1] = "X";
                result[2] = "Y";
                result[3] = "Z";
                break;
            default:
                result = null;
                break;
        }
        return result;
    }

}
